//
//  DATAsyncGetAFNBlock.m
//  AFNBlockDemo
//
//  Created by dllo on 15/10/12.
//  Copyright (c) 2015年 ShangRJ. All rights reserved.
//

#import "DATAsyncGetAFNBlock.h"


@interface DATAsyncGetAFNBlock ()

@property (nonatomic, copy) GetAFNBlockResult resultBlock;

@end

@implementation DATAsyncGetAFNBlock


+(void)GetAFNURLWithString:(NSString *)url andBody:(NSDictionary *)body andCookie:(NSString *)cookie resultBlock:(GetAFNBlockResult)resultBlock errorBlock:(GetAFNBlockError)errorBlock{
    DATAsyncGetAFNBlock *getAfn = [[DATAsyncGetAFNBlock alloc] init];
    [getAfn getAFNURLWithString:url andBody:body andCookie:cookie resultBlock:resultBlock errorBlock:errorBlock];
    
    //    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    //
    //    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    //    [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    //
    //        resultBlock(responseObject);
    //    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    //
    //        errorBlock(error);
    //    }];
    
    
    
    
}

- (void)getAFNURLWithString:(NSString *)url andBody:(NSDictionary *)body andCookie:(NSString *)cookie resultBlock:(GetAFNBlockResult)resultBlock errorBlock:(GetAFNBlockError)errorBlock {
    
    
    self.resultBlock = resultBlock;
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [[AFHTTPRequestSerializer alloc] init];
    [manager.requestSerializer setValue:cookie forHTTPHeaderField:@"Cookie"];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    
    [manager GET:url parameters:body success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        
        
        self.resultBlock(responseObject);
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
        errorBlock(error);
    }];
}

@end
